package service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import model.EstpInfo;
import model.Experience;
import model.User;

import dao.ExperienceDao;

import service.ExperienceManager;

public class ExperienceManagerImpl implements ExperienceManager {
	private ExperienceDao experienceDao;
	public ExperienceDao getExperienceDao() {
		return experienceDao;
	}
	public void setExperienceDao(ExperienceDao experienceDao) {
		this.experienceDao = experienceDao;
	}
	public int addExperienceManager(Date beginTime, Date endTime,
			String ejaddress, int job) throws Exception {
		// TODO Auto-generated method stub
		try {
			Experience ex = new Experience();
			ex.setBeginTime(beginTime);
			ex.setEndTime(endTime);
			ex.setEjaddress(ejaddress);
			ex.setJob(job);
			Map session = ActionContext.getContext().getSession();
			User user = (User)session.get("USER");
			ex.setUser(user);
			experienceDao.save(ex);
			return ex.getId();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("新增个人经历时出现异常");
		}
		
	}
	
//	public int addOrUpdateExperienceManager(Date beginTime, Date endTime,
//			String ejaddress, int job) throws Exception {
//		// TODO Auto-generated method stub
//		try {
//			Map session = ActionContext.getContext().getSession();
//			Experience ex = (Experience)session.get("EX");
//			if(ex == null){
//				ex = new Experience();
//			}
//			ex.setBeginTime(beginTime);
//			ex.setEndTime(endTime);
//			ex.setEjaddress(ejaddress);
//			ex.setJob(job);
//			User user = (User)session.get("USER");
//			ex.setUser(user);
//			experienceDao.saveOrUpdate(ex);
//			return ex.getId();
//		} catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//			throw new Exception("新增或更新个人经历时出现异常");
//		}
//		
//	}

	public List<Experience> getExperienceByUser(User user) throws Exception{
		try {
			List<Experience> eInfo = experienceDao.getExperienceByUser(user);
			return eInfo;
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("按用户查找工作经历信息时出现异常");
		}
	}
	public void delAllInfo() throws Exception{
		try {
			Map session = ActionContext.getContext().getSession();
			User user = (User)session.get("USER");
			experienceDao.delete(user);
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("删除工作经历信息时出现异常");
		}
	}
}
